<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Try to prevent user from closing window</title>
<meta name="generator" content="editplus">
<meta name="author" content="huangwei.bupt@gmail.com">
</head>
<body>
<script language="javascript">
<!--
window.onbeforeunload = function (e) {
	if(window.event){ // non-FF fix
		e = event || window.event;
	}
    /*
	alert(e.clientX);
	alert(e.clientY);
	alert( document.body.clientWidth);
	alert( document.body.clientHeight);
    */

	if(e.clientX && e.clientY) {
		if(e.clientX > document.body.clientWidth || // Close Window
		   e.clientY > document.body.clientHeight || 
		   e.clientY<0 ||  // Close Tab
		   e.altKey)  // Alt-F4 in case
		{ 
			alert("You can't close this window!");
			window.open("http://www.yahoo.cn");
		} 
		else
		{
			//alert("exception!");
		}
	}
	else
	{
			//alert("You can't close this window!");
			window.open("http://www.yahoo.cn"); // FF 3.0 does not work!
			e.returnValue = "Warning: You have unsaved data before you leave!";
	}
    //e.returnValue = "Warning: You have unsaved data before you leave!";
}

//-->
</script>
Test!
</body>
</html>

